package com.situ.controller.user;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.situ.entity.bas_dict.BasDict;
import com.situ.entity.cst_service.CstService;
import com.situ.entity.customer.CstCustomer;
import com.situ.entity.might.SysMight;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.situ.service.user.SysUserService;
import com.situ.entity.user.SysUser;
import com.situ.util.*;

import java.util.List;

/**
 * SysUser的路由接口服务
 * 
 * @author胡文
 *
 */
//
@RestController
public class SysUserController {

	/** SysUserService服务 */
	@Autowired
	private SysUserService sysUserService;
	
	/**
	 * 查询所有SysUser数据的方法
	 * @param value
	 * @return
	 */
	@RequestMapping(value = "/SysUser/query", produces = {"application/json;charset=UTF-8"})
	public ResponseData query(SysUser value) {

		return ResponseData.ok().putDataValue("list",sysUserService.find(value));
	}
	
	/**
	 * 通过id查询SysUser数据的方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysUser/queryById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData queryById(@PathVariable(name="id") Long id) {
		 return ResponseData.ok().putDataValue("obj",sysUserService.findOne(id));
	}
	
	/**
	 * 插入SysUser属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysUser/save")
	public ResponseData save(SysUser value) {
		return ResponseData.ok().putDataValue("obj", sysUserService.saveNotNull(value));
	}
	
	/**
	 * 更新SysUser属性不为空的数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysUser/update", produces = {"application/json;charset=UTF-8"})
	public ResponseData update(SysUser value) {
		return ResponseData.ok().putDataValue("obj",sysUserService.updateNotNullById(value));
	}

	/**
	 * 通过id删除SysUser数据方法
	 * 
	 * @return
	 */
	@RequestMapping(value = "/SysUser/delById/{id}", produces = {"application/json;charset=UTF-8"})
	public ResponseData delById(@PathVariable(name="id") Long id) {
		return ResponseData.ok().putDataValue("obj",sysUserService.deleteById(id));
	}


    //带分页的查询全部
//@ApiOperation("带分页的查询全部")

    @RequestMapping(value = "/SysUser/queryPage", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryPage(SysUser value,
                                  @RequestParam(defaultValue = "1",required = false) int pageNum ,
                                  @RequestParam(defaultValue = "5",required = false) int pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<SysUser> list = sysUserService.queryByLike(value);
        PageInfo pageInfo = new PageInfo<SysUser>(list,5);
        return ResponseData.ok()
                // .putDataValue("list", list)
                .putDataValue("pageInfo",pageInfo);
    }
    //登录
    @RequestMapping(value = "/login", produces = {"application/json;charset=UTF-8"})
    public ResponseData login(SysUser user){
            return ResponseData.ok().putDataValue("sysUsers", sysUserService.query(user));
    }
    //用户编辑
    @RequestMapping(value = "/queryByUsrId/{usrId}", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryByUsrId(@PathVariable int usrId){
        return ResponseData.ok().putDataValue("user", sysUserService.queryByUsrId(usrId));
    }
    //用户编辑保存
    @RequestMapping(value = "/myAdd", produces = {"application/json;charset=UTF-8"})
    public ResponseData myAdd(SysUser sysUser){
        return ResponseData.ok().putDataValue("i", sysUserService.myAdd(sysUser));
    }
    //用户删除
    @RequestMapping(value = "/deleteUserById/{usrId}", produces = {"application/json;charset=UTF-8"})
    public ResponseData deleteUserById(@PathVariable int usrId){
        return ResponseData.ok().putDataValue("i", sysUserService.deleteUserById(usrId));
    }
    //用户添加
    @RequestMapping(value = "/addUser", produces = {"application/json;charset=UTF-8"})
    public ResponseData addUser(SysUser sysUser){
        return ResponseData.ok().putDataValue("i", sysUserService.addUser(sysUser));
    }
    @PostMapping(value = "/SysUser/update", produces = {"application/json;charset=UTF-8"})
    public ResponseData updateUser(SysUser sysUser){
        return ResponseData.ok().putDataValue("i", sysUserService.updateUser(sysUser));
    }

    @RequestMapping(value = "/SysUser/queryById2/{id}", produces = {"application/json;charset=UTF-8"})
    public ResponseData queryById2(@PathVariable(name="id") Long id) {
        SysUser user = sysUserService.findOne(id);
        return ResponseData.ok().putDataValue("obj",user.getUsr_name());
    }

    @RequestMapping("/CstCustomer/selectuser")
    public List<SysUser> querydiqu(SysUser value) {
        List<SysUser> list = sysUserService.selectflag(value);
        return list;
    }




}
